package com.neusoft.a312cxy.android18cxy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.adapter.tuikuanAdapter;
import com.neusoft.a312cxy.android18cxy.adapter.weiwanchengAdapter;
import com.neusoft.a312cxy.android18cxy.adapter.yiwanchengAdapter;
import com.neusoft.a312cxy.android18cxy.bean.Orderlist;
import com.neusoft.a312cxy.android18cxy.model.MySelfModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Young on 2017/10/31.
 */

public class OrderlistActivity extends AppCompatActivity {
    private RecyclerView weiwancheng, yiwancheng, tuikuan;
    private String userid;
    private List mDatelist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderlist);
        initView();
        saveDate();
        GetOrder();
        GetyiwanchengOrder();
        GettuikuanOrder();
    }


    public void initView() {

        weiwancheng = (RecyclerView) findViewById(R.id.weiwancheng);
        weiwancheng.setLayoutManager(new LinearLayoutManager(OrderlistActivity.this));
        weiwancheng.setItemAnimator(new DefaultItemAnimator());

        yiwancheng = (RecyclerView) findViewById(R.id.yiwancheng);
        yiwancheng.setLayoutManager(new LinearLayoutManager(OrderlistActivity.this));
        yiwancheng.setItemAnimator(new DefaultItemAnimator());

        tuikuan = (RecyclerView) findViewById(R.id.tuikuan);
        tuikuan.setLayoutManager(new LinearLayoutManager(OrderlistActivity.this));
        tuikuan.setItemAnimator(new DefaultItemAnimator());
    }

    public void saveDate() {

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        //  shaitu_id = bundle.getString("shaitu_id");
        userid = bundle.getString("userid");
    }
//未完成订单
    public void GetOrder() {
        final MySelfModel MySelfModel=new MySelfModel();
        Call<List<Orderlist>> call=MySelfModel.getOrderlist("19","0",1);
        call.enqueue(new Callback<List<Orderlist>>() {
            @Override
            public void onResponse(Call<List<Orderlist>> call, Response<List<Orderlist>> response) {
                mDatelist = response.body();

                weiwanchengAdapter adapter = new weiwanchengAdapter(OrderlistActivity.this, mDatelist);


                yiwancheng.setAdapter(adapter);
            }
            @Override
            public void onFailure(Call<List<Orderlist>> call, Throwable t) {

            }
        });

        }
//已完成订单
    public void GetyiwanchengOrder() {
        final MySelfModel MySelfModel=new MySelfModel();
        Call<List<Orderlist>> call=MySelfModel.getOrderlist("19","1",1);
        call.enqueue(new Callback<List<Orderlist>>() {
            @Override
            public void onResponse(Call<List<Orderlist>> call, Response<List<Orderlist>> response) {
                mDatelist = response.body();

                yiwanchengAdapter adapter = new yiwanchengAdapter(OrderlistActivity.this, mDatelist);


                weiwancheng.setAdapter(adapter);
            }
            @Override
            public void onFailure(Call<List<Orderlist>> call, Throwable t) {

            }
        });

    }

    //退款订单
    public void GettuikuanOrder() {
        final MySelfModel MySelfModel=new MySelfModel();
        Call<List<Orderlist>> call=MySelfModel.getOrderlist("19","3",1);
        call.enqueue(new Callback<List<Orderlist>>() {
            @Override
            public void onResponse(Call<List<Orderlist>> call, Response<List<Orderlist>> response) {
                mDatelist = response.body();

                tuikuanAdapter adapter = new tuikuanAdapter(OrderlistActivity.this, mDatelist);


                weiwancheng.setAdapter(adapter);
            }
            @Override
            public void onFailure(Call<List<Orderlist>> call, Throwable t) {

            }
        });

    }
    }
